using System.Collections.Generic;
using System.Data.Linq;

namespace Magiq.Sql.Tests.TestModel {
    public class Parent {
        private EntitySet<ChildItem> items;

        public Parent() {
            Items = new EntitySet<ChildItem>();
        }

        public int Id { get; set; }
        public string Name { get; set; }

        public IList<ChildItem> Items {
            get {
                if (items == null)
                    items = new EntitySet<ChildItem>();
                return items;
            }
            set {
                if (value is EntitySet<ChildItem>) {
                    items = (EntitySet<ChildItem>) value;
                }
                else {
                    var e = new EntitySet<ChildItem>();
                    e.AddRange(value);
                    items = e;
                }
            }
        }

        public void AddItem(ChildItem item) {
            Items.Add(item);
        }
    }
}